<template>
  <div>
    <top-bar></top-bar>
    <left-bar :datas='data'></left-bar>
    <div class="system">
      <home-bar :currentPage='currentPage'></home-bar>
      <div class="order-main system-main">
        <div class="main-position">
          首页 > 资讯中心 > 文章详情
          <a href="javascript:void(0);"><i class="el-icon-refresh"></i></a>
        </div>
        <div class="main-height"></div>
        <div class="main-mains">
          <div class="main-top-nav">
            <ul>
              <router-link to="/relationsList/0" @click.native="addPath('/relationsList/0','资讯中心','平台公告')">
                <li >平台公告</li>
              </router-link>
              <router-link to="/relationsList/1" @click.native="addPath('/relationsList/1','资讯中心','医药咨询')">
                <li >医药咨询</li>
              </router-link>
              <router-link to="/relationsList/2" @click.native="addPath('/relationsList/2','资讯中心','商学院')">
                <li >商学院</li>
              </router-link>
              <router-link to="/relationsList/3" @click.native="addPath('/relationsList/3','资讯中心','安全保障')">
                <li >安全保障</li>
              </router-link>
              <router-link to="/relationsList/4" @click.native="addPath('/relationsList/4','资讯中心','常见问题')">
                <li >常见问题</li>
              </router-link>
            </ul>
          </div>
          <div class="relationsDetailMain">
            <div class="inner-return">
              <i class="el-icon-arrow-left" @click="returns()"></i> <span @click="returns()">资讯列表</span>
            </div>
            <h1>{{title}}</h1>
            <div class="releaseMsg">{{time | times}} | 作者：{{author}} | 点击次数 ：{{num}}次</div>
            <div class="articleContent" v-html="content">
        
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import topBar from "../public/top";
import leftBar from "../public/left";
import homeBar from "../public/homebar";
export default {
  components: {
    leftBar,
    topBar,
    homeBar
  },
  data() {
    return {
      data: "/relations",
      title: "",
      time: "",
      author: "",
      num: "",
      content: ""
    };
  },
  methods: {
    addPath(n1, n2, n3, nums) {
      //点击切换home-bar
      var obj = {};
      obj.n1 = n1;
      obj.n2 = n2;
      this.$store.commit("addPath", obj);
    },
    returns() {
      //返回
      history.go(-1);
    },
    detalis(num) {
      let _this = this;
      let ourls =
        this.urls +
        "/adm/user/refreshToken/" +
        localStorage.getItem("uid") +
        "/" +
        localStorage.getItem("token");
      checkTime(
        new Date().getTime() / 1000,
        ourls,
        localStorage.getItem("reToken")
      );
      _this
        .$http({
          url:
            _this.urls +
            "/who/Article/getOneList/" +
            localStorage.getItem("uid") +
            "/" +
            localStorage.getItem("token"),
          method: "post",
          data: {
            id: num
          }
        })
        .then(function(res) {
          let data = res.data;
          if (data.code == "1") {
            _this.title = data.data.title;
            _this.author = data.data.author;
            _this.time = data.data.update_time;
            _this.num = data.data.click_num;
            _this.content = data.data.content;
          } else {
            invalid(data.msg);
            _this.$message.error(data.msg);
          }
        })
        .catch(function(error) {
          console.log(error);
        });
    }
  },
  activated() {
    this.detalis(this.$route.params.id);
  },
  filters: {
    times(value) {
      var time = new Date(value * 1000);
      var month =
        time.getMonth() + 1 > 9
          ? time.getMonth() + 1
          : "0" + (time.getMonth() + 1);
      var data = time.getDate() > 9 ? time.getDate() : "0" + time.getDate();
      var hour = time.getHours() > 9 ? time.getHours() : "0" + time.getHours();
      var minutes =
        time.getMinutes() > 9 ? time.getMinutes() : "0" + time.getMinutes();
      var second =
        time.getSeconds() > 9 ? time.getSeconds() : "0" + time.getSeconds();
      var times =
        time.getFullYear() +
        "-" +
        month +
        "-" +
        data +
        " " +
        hour +
        ":" +
        minutes +
        ":" +
        second;
      return times;
    }
  }
};
</script>

<style lang="less">
@import "relations.less";
</style>
